package org.electronic.registration.util

import org.electronic.registration.bo.Doctor
import org.electronic.registration.bo.Scheduler
import org.electronic.registration.dao.DoctorDao
import org.electronic.registration.dao.SchedulerDao
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner

/**
 * User: Egor
 * Date: 04.02.12
 */
@Ignore
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext.xml")
class GenerateScheduler {

    @Autowired
    SchedulerDao schedulerDao;

    @Autowired
    DoctorDao doctorDao;

    @Test
    public void testGetSchedulerForDoctor() {
        Random random = new Random();
        List<Doctor> docList = doctorDao.getAllDoctors();
        for (Doctor doctor: docList) {

            for (int i = 0; i < 1500; i++) {
                GregorianCalendar calendar = (GregorianCalendar) TestUtil.getTodayEightAm();
                calendar.add(GregorianCalendar.MINUTE, 15 * i);
                if (calendar.get(GregorianCalendar.HOUR_OF_DAY) > 17 || calendar.get(GregorianCalendar.HOUR_OF_DAY) < 8) {
                    continue;
                }

                int weekend1 = random.nextInt(6) + 1;
                int weekend2 = random.nextInt(6) + 1;
                if (calendar.get(GregorianCalendar.DAY_OF_WEEK) == GregorianCalendar.SATURDAY ||
                        calendar.get(GregorianCalendar.DAY_OF_WEEK) == GregorianCalendar.SATURDAY ||
                        calendar.get(GregorianCalendar.DAY_OF_WEEK) == weekend1 ||
                        calendar.get(GregorianCalendar.DAY_OF_WEEK) == weekend2) {
                    continue;
                }

                Scheduler scheduler = new Scheduler();
                scheduler.setDoctor(doctor);
                scheduler.setStartDate(calendar.getTime());
                calendar.add(GregorianCalendar.MINUTE, 15);
                scheduler.setEndDate(calendar.getTime());
                schedulerDao.save(scheduler);
            }
        }
    }
}
